package com.xx.java8.domain;

import com.xx.java8.chapter3.App;
import com.xx.java8.enums.ColorEnum;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

@Data
public class Apple implements Serializable {
    private static final long serialVersionUID = -3277350989021900438L;

    private Double weight;

    private ColorEnum color;

    public Apple() {
    }

    public Apple(Double weight) {
        this.weight = weight;
    }

    public boolean isGreen() {
        return this.getColor().getName().equals(ColorEnum.GREEN.getName());
    }

    public static List<Apple> filter(List<Apple> appleList, Predicate<Apple> applePredicate) {
        List<Apple> result = new ArrayList<>();
        for (Apple apple : appleList) {
            if (applePredicate.test(apple)) {
                result.add(apple);
            }
        }
        return result;
    }
}
